//
//  AXFTypeView.m
//  aixinfeng005
//
//  Created by zhanghaifeng on 16/10/11.
//  Copyright © 2016年 BBSWaitting. All rights reserved.
//

#import "AXFTypeView.h"
#import "AXFTypeFlowLayout.h"
#import "AXFTypeCollectionViewCell.h"

static NSString *typeCellID = @"typeCellID";

@interface AXFTypeView()<UICollectionViewDataSource, UICollectionViewDelegate>

@end

@implementation AXFTypeView

- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    
    return self;
}

- (void)setupUI{
    
    // 创建自定义流布局对象
    AXFTypeFlowLayout *flowLayout = [[AXFTypeFlowLayout alloc] init];
    // 创建collectionView
    UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, 70) collectionViewLayout:flowLayout];
    
    collectionView.backgroundColor = [UIColor whiteColor];
    
    // 添加到控制器的view上
    [self addSubview:collectionView];
    
    
    // 设置数据源和代理
    collectionView.delegate = self;
    collectionView.dataSource = self;
    
    // 注册cell
    [collectionView registerClass:[AXFTypeCollectionViewCell class] forCellWithReuseIdentifier:typeCellID];
    
}

/// 返回多少个格子
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _typeData.count;
}

/// 返回每个格子的内容
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    AXFTypeCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:typeCellID forIndexPath:indexPath];
    
    cell.typeModel = _typeData[indexPath.row];
    
    return cell;
}

@end
